//服务器地址
var hostUrl = 'https://api.aicashloanindia.com'
var lang = GetQueryValue('lang') || 'cn'

//网站配置
var configInfo = {}

// 获取 URL 参数
function GetQueryValue(queryName) {
    var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    } else {
        return null;
    }
}
// 导航栏展示高亮
function NavHeight(list, type) {
    list.each(function (index, item) {
        switch (type) {
            case '0':
                $(list[0]).find('a').addClass('active')
                break;
            case '1':
                $(list[0]).find('a').addClass('active')
                break;
            case '2':
                $(list[0]).find('a').addClass('active')
                break;
            case '3':
                $(list[0]).find('a').addClass('active')
                break;
            case '4':
                $(list[1]).find('a').addClass('active')
                break;
            case '5':
                $(list[1]).find('a').addClass('active')
                break;
            case '6':
                $(list[1]).find('a').addClass('active')
                break;
            case '7':
                $(list[1]).find('a').addClass('active')
                break;
            case '8':
                $(list[2]).find('a').addClass('active')
                break;
            case '9':
                $(list[2]).find('a').addClass('active')
                break;

            default:
                break;
        }
    })
}

//ajax 公共方法

function handleAjax(url, params, callback, type = 'post', async = false) {
    $.ajax({
        url: hostUrl + url,
        data: params,
        type,
        dataType: "json",
        async,
        success: function (data) {
            callback && callback(data)
        }
    })
}
/**
 *  将时间戳转换成日期格式
 *  参数 fmt  格式类似： yyyy-MM-dd     或者 yyyy-MM-dd hh:mm
 */
function dateFilter(time, fmt) {
    if (!time) return
    if ((time + "").length == 10) time = time * 1000;  //10位 是秒  13位毫秒
    let date = new Date(Number(time));
    if (!date) return '';
    if (!fmt) fmt = 'yyyy-MM-dd';
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    }
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + ''
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str))
        }
    }
    return fmt
}
function padLeftZero(str) {
    return ('00' + str).substr(str.length)
}


// handleAjax("/index/config/getConfigInfo", {}, onInit)
function onInit(params) {
    if(params.success) {
        configInfo = params.data
        
        if(lang == 'cn') {
            document.title = configInfo.name || "EXPLORE SHANGHAI";
        }else{
            document.title = configInfo.en_name || "EXPLORE SHANGHAI";
        }

        if(getconfigInfo) getconfigInfo(configInfo)
    }
    // console.log(888, params)
}


//全屏
function fullScreen() {
    var element = document.documentElement;
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    }
}

//退出全屏 
function exitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}